<?php
include "includes/ui.php";

echo headerHTML("master","กำหนดเกณฑ์อายุ");
?> 
<link href='css/datepicker.css' rel='stylesheet' tyle="text/css">
<!-- Live Stats -->
<div class="row-fluid">

    <!-- Pie: Box -->
    <div class="span12">

        <!--  : Top Bar -->
        <div class="top-bar">
            <h3><i class="icon-cog"></i> กำหนดเกณฑ์อายุ</h3>
           
        </div>
        <!-- /  : Top Bar -->



        <!-- Pie: Content -->
        <div class="well no-padding" >
			<div class="row-fluid">
			 <form class="form-horizontal" style="margin-bottom:0px;" >
				<div class="control-group" style="">
					<label class="control-label" style='padding-top:5px;'><i class="icon-double-angle-right"></i> เกณฑ์อายุ </label>
					<div class="controls" >
						<input type="text" id="txtAge" readonly required data-date-format="dd-mm" data-date-viewmode="1" data-date-minviewmode="0" placeholder="31-07" /> &nbsp;
						<span class="help-inline">(วัน-เดือน) &nbsp;&nbsp;&nbsp; อัพเดทล่าสุด :  <span style='color:red;' id='lblLastUpdate'></span></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<button class="btn btn-success" id="btnSave" type='submit' style='margin-left:50px;'> บันทึก</button>
					</div>
				</div>
 
				<div class="well" style="margin-bottom:0px;padding-bottom:40px;" >
				<table class="table table-bordered" id="historydata">
					 <thead>
						<tr>
						  <th style='width:100px;'>#</th>
						  <th >เกณฑ์อายุ (วัน-เดือน)</th>
						  <th style='width:250px;'>วันที่แก้ไข</th>
						  <th style='width:250px;'>แก้ไขโดย</th>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
			 
				</div>
		</form>
        <!-- / Pie: Content -->

		</div>
    <!-- / Pie -->

</div>
<!-- / Live Stats -->

<?php
echo footerHTML();
?>

<!-- Javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src='js/jquery.hotkeys.js'></script>
<!--script src='js/fullcalendar.min.js'></script-->
<script src="js/jquery-ui-1.10.2.custom.min.js"></script>
<script src="js/jquery.pajinate.js"></script>
<!--script src="js/jquery.prism.min.js"></script-->
<script src="js/jquery.dataTables.min.js"></script>

<script src="js/jquery.flot.resize.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-wysiwyg.js"></script>
<!--script src="js/bootstrap-typeahead.js"></script-->
<script src="js/jquery.easing.min.js"></script>
<script src="js/jquery.chosen.min.js"></script>
<script src="js/avocado-custom.js"></script>
<script src="js/jqBootstrapValidation.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script>
$(function() {

	 var url='controls/master_model.php';
	 LoadData();
	$('#txtAge').datepicker();
	
	$("#btnSave").click(function(){
		$("#txtAge").jqBootstrapValidation({preventSubmit: false,
			submitSuccess: function ($form, event) { event.preventDefault();}
		}); 
		 
		var _date = $.trim($("#txtAge").val());	
		 
		var dataSet;
		if (_date!=""){	
			dataSet={"m":"age","dateAge":_date};  
			$.ajax({
				type: 'POST',
				cache: false,
				url: url,
				data: dataSet,
				success: function(data){
					$("#popup").modal('hide');
					LoadData();
				}
			});
			
		}
		 $("#txtAge").jqBootstrapValidation("destroy");
	});
	function LoadData(){
		$( "#historydata tbody tr" ).remove();
 
        
        $('#historydata').dataTable( {
			"bProcessing": true,
			"bFilter": false,
			"bLengthChange": false,
			"sAjaxSource": url,
			"oLanguage": {
				"sEmptyTable":     "ไม่พบข้อมูล"
			},
			"bDestroy": true,
			"sServerMethod": "POST",
			"fnServerParams": function ( aoData ) {
					aoData.push( { "name": "m", "value": "load_age" });
				},
			"aoColumnDefs":[
				{   "bSortable": false, "aTargets": [ 1 ] ,"sClass":"left"},	
				{   "bSortable": false, "aTargets": [ 2 ] ,"sClass":"center" },	
				{   "bSortable": false, "aTargets": [ 3 ] ,"sClass":"center" },	
				 
			],"fnDrawCallback": function ( oSettings ) {
				 var that = this;
				/* Need to redo the counters if filtered or sorted */
                 var iTotalRecords = oSettings.fnRecordsTotal();
				//alert(oSettings.aiDisplay.length + ' ' + iTotalRecords);
				 
					if (iTotalRecords > 0){ 	
						if ( oSettings.bSorted || oSettings.bFiltered )
						{
							$("#lblLastUpdate").html(oSettings.aoData[0]._aData[2]);
							for ( var i=0, iLen=oSettings.aiDisplay.length ; i<iLen ; i++ )
							{
								$('td:eq(0)', oSettings.aoData[ oSettings.aiDisplay[i] ].nTr ).html( i+1 );
							}
						}
					}
					 
				} 
		 } );
	}
});
</script>
</html>